package Part1_InetAddress;

import org.junit.Test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * ClassName: Demo
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.04.24 19:44
 */
public class Demo {
    @Test
    public void test1() {

        try {
            //1、实例化:getByName("192.168.24.198")
            InetAddress inet1 = InetAddress.getByName("120.240.51.36");
            InetAddress inet2 = InetAddress.getByName("www.vip.com");//走DNS解析出了ipv4

            System.out.println(inet2);

            InetAddress localHost = InetAddress.getLocalHost();
            InetAddress localHost1 = InetAddress.getByName("127.0.0.1");

            System.out.println(localHost);//本机ip

            System.out.println(inet2.getHostName());//www.vip.com
            System.out.println(inet2.getHostAddress());//120.240.51.33


        } catch (UnknownHostException e) {
            e.printStackTrace();
        }


    }
}
